<?php

// define root of the project
define( 'VIDOOP_SECURE_ROOT', dirname(dirname(dirname(dirname(dirname(__FILE__))))) );
set_include_path( VIDOOP_SECURE_ROOT . PATH_SEPARATOR . get_include_path());

error_reporting(E_ALL);
ini_set('display_errors', true);

require_once 'PHPUnit/Framework.php';
require_once 'Auth/Vidoop/Secure.php';


abstract class Auth_Vidoop_Secure_TestCase extends PHPUnit_Framework_TestCase {

	protected $data_dir;

	protected $config;

	protected $vs;

	public function __construct() {
		parent::__construct();

		$this->data_dir = VIDOOP_SECURE_ROOT . '/test/data/';

		// load config if present
		$config_file = VIDOOP_SECURE_ROOT . '/test/config.php';
		if (file_exists($config_file)) {
			include $config_file;
			$this->config = $config;
		} else {
			$this->config = array();
		}

		// ensure api_base doesn't have a trailing slash
		if (substr($this->config['base'], -1) == '/') {
			$this->config['base'] = substr($this->config['base'], 0, -1);
		}
	}

	protected function init_vidoop_secure() {
		if ($this->vs == null) {
			$this->vs = new Auth_Vidoop_Secure($this->config['customer'], null, $this->config['base']);
			$this->vs->setDebug(true);
			$this->vs->site($this->config['site'], $this->config['username'], $this->config['password']);
		}
	}

	protected function get_service($service) {
		$this->init_vidoop_secure();
		return $this->vs->get_service($service);
	}
}

?>
